package com.hl.card.modular.packBack.controller;

import com.baomidou.mybatisplus.plugins.Page;
import com.hl.card.common.controller.BaseController;
import com.hl.card.common.persistence.model.Integrate;
import com.hl.card.modular.pack.service.IntegrateService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.hl.card.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * integrate控制器
 *
 * @author yjx
 * @Date 2019-01-19 16:22:12
 */
@Controller
@RequestMapping("/integrate")
public class IntegrateController extends BaseController {

    private String PREFIX = "/packback/integrate/";
    @Autowired
    private IntegrateService integrateService;
    /**
     * 跳转到integrate首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "integrate.html";
    }
    /**
     * 跳转到添加integrate
     */
    @RequestMapping("/integrate_add")
    public String integrateAdd() {
        return PREFIX + "integrate_add.html";
    }
    /**
     * 跳转到修改integrate
     */
    @RequestMapping("/integrate_update/{integrateId}")
    public String integrateUpdate(@PathVariable Integer integrateId, Model model) {
        Integrate integrate = integrateService.selectById(integrateId);
        model.addAttribute("item",integrate);
        LogObjectHolder.me().set(integrate);
        return PREFIX + "integrate_edit.html";
    }
    /**
     * 获取integrate列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(Integrate integrate,@RequestParam(required = false)  String beginTime,
                       @RequestParam(required = false)  String endTime,
                       @RequestParam(required = false,name = "uname")  String uname
                       ) {
        integrate.setName(uname);
        Page<Integrate> dPage = integrateService.selectMultiCondition(integrate,beginTime,endTime);
        List<Integrate> integrateList=dPage.getRecords();
        Map<String, Object> jsonMap = new HashMap<>();
        jsonMap.put("total", dPage.getTotal());
        jsonMap.put("rows", integrateList);
        return jsonMap;
    }
    /**
     * 新增integrate
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(Integrate integrate) {
        integrateService.insert(integrate);
        return SUCCESS_TIP;
    }
    /**
     * 删除integrate
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer integrateId) {
        integrateService.deleteById(integrateId);
        return SUCCESS_TIP;
    }
    /**
     * 修改integrate
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(Integrate integrate) {
        integrateService.updateById(integrate);
        return SUCCESS_TIP;
    }
    /**
     * integrate详情
     */
    @RequestMapping(value = "/detail/{integrateId}")
    @ResponseBody
    public Object detail(@PathVariable("integrateId") Integer integrateId) {
        return integrateService.selectById(integrateId);
    }

}
